package com.xeem.core.utils
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	
	public class ProcessData extends EventDispatcher
	{
		private var url:String;
		private var parse:ParseData;
		private var _dataFormat:String;
		private var _data:Object;
				
		public function ProcessData()
		{
			
		}
		
		/**
		 * 载入xml
		 * @param	$url
		 */
		public function load($url:String):void
		{
			url = $url;
			var urlloader:URLLoader = new URLLoader(new URLRequest(url));
			if (null!=_dataFormat)
				urlloader.dataFormat =_dataFormat ;
			urlloader.addEventListener(Event.COMPLETE, onLoadDone);
		}		
		
		/**
		 * 载入完毕
		 * @param	e
		 * @return  void
		 */
		private function onLoadDone(e:Event):void
		{
			(e.currentTarget as URLLoader).removeEventListener(Event.COMPLETE, onLoadDone);
			_data=e.currentTarget.data;
			trace(_data);
			parse.parseData(_data);
		}
		
		public function get data(){
			return _data;
		}
		
		public function set parseClazz(parseData:ParseData){
			parse=parseData;
		}
		
		public function  get dataFormat(){
			return _dataFormat;
		}
		
		public function set dataFormat($dataFormat:String){
			_dataFormat=$dataFormat;
		}
		
	}
}